<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>商品编辑</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/layuimini.css?v=2.0.4.2}" media="all">
    <link rel="stylesheet" th:href="@{/css/themes/default.css}" media="all">
    <link rel="stylesheet" th:href="@{/lib/font-awesome-4.7.0/css/font-awesome.min.css}" media="all">
    <style>

        body{
            padding: 20px;
        }


    </style>
</head>
<body>
<form class="layui-form" action="" th:object="${goods}">
    <input type="hidden" th:field="*{id}">
    <div class="layui-form-item">
        <label class="layui-form-label">货物编号</label>
        <div class="layui-input-block">

            <input type="text" th:field="*{commodity}"  required="required"  lay-verify="required" placeholder="请输入货物编号" autocomplete="off" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">货物类型</label>
        <div class="layui-input-block">
            <input type="radio" th:field="*{species}" value="CPU" title="CPU">
            <input type="radio" th:field="*{species}" value="主板" title="主板">
            <input type="radio" th:field="*{species}" value="显卡" title="显卡">
            <input type="radio" th:field="*{species}" value="内存" title="内存">
            <input type="radio" th:field="*{species}" value="固态硬盘" title="固态硬盘">
            <input type="radio" th:field="*{species}" value="机械硬盘" title="机械硬盘">
            <input type="radio" th:field="*{species}" value="散热器" title="散热器">
            <input type="radio" th:field="*{species}" value="散热风扇" title="散热风扇">
            <input type="radio" th:field="*{species}" value="电源" title="电源">
            <input type="radio" th:field="*{species}" value="机箱" title="机箱">
            <input type="radio" th:field="*{species}" value="显示器" title="显示器">
            <input type="radio" th:field="*{species}" value="键盘" title="键盘">
            <input type="radio" th:field="*{species}" value="鼠标" title="鼠标">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">货物品牌</label>
        <div class="layui-input-block">
            <input type="radio" th:field="*{brand}" value="华硕（ASUS)" title="华硕（ASUS）">
            <input type="radio" th:field="*{brand}" value="微星（MSI)" title="微星（MSI）">
            <input type="radio" th:field="*{brand}" value="技嘉（GIGABYTE）" title="技嘉 （GIGABYTE）">
            <input type="radio" th:field="*{brand}" value="七彩虹（Colorful）" title="七彩虹（Colorful）">
            <input type="radio" th:field="*{brand}" value="英特尔（Intel）" title="英特尔（Intel）">
            <input type="radio" th:field="*{brand}" value="铭瑄（MAXSUN）" title="铭瑄（MAXSUN）">
            <input type="radio" th:field="*{brand}" value="影驰（Galaxy）" title="影驰（Galaxy）">
            <input type="radio" th:field="*{brand}" value="金士顿 (Kingston)" title="金士顿 (Kingston)">
            <input type="radio" th:field="*{brand}" value="三星（SAMSUNG）" title="三星 （SAMSUNG）">
            <input type="radio" th:field="*{brand}" value="西部数据（Western Digital）" title="西部数据（Western Digital）">
            <input type="radio" th:field="*{brand}" value="联想（Lenovo)" title="联想（Lenovo) ">
            <input type="radio" th:field="*{brand}" value="光威（Gloway）" title="光威（Gloway）">
            <input type="radio" th:field="*{brand}" value="先马（SAMA）" title="先马（SAMA）">
            <input type="radio" th:field="*{brand}" value="长城（Great Wall）" title="长城（Great Wall））">
            <input type="radio" th:field="*{brand}" value="罗技（G）" title="罗技（G）">
            <input type="radio" th:field="*{brand}" value="其他" title="其他">

        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">货物名称</label>
        <div class="layui-input-block">
            <input type="text" th:field="*{name}" required="required"  lay-verify="required" placeholder="请输入货物名称" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">货物规格</label>
        <div class="layui-input-block">
            <input type="radio" th:field="*{specifications}" value="全新" title="全新">
            <input type="radio" th:field="*{specifications}" value="9成新" title="9成新">
            <input type="radio" th:field="*{specifications}" value="女生自用99新" title="女生自用99新">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">供应商</label>
        <div class="layui-input-block">
            <input type="text" th:field="*{supplier}" required="required"  lay-verify="required" placeholder="请输入供应商名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">存放仓库</label>
        <div class="layui-input-block">
            <input type="radio" th:field="*{warehouse}" value="A仓库" title="A仓库">
            <input type="radio" th:field="*{warehouse}" value="B仓库" title="B仓库">
            <input type="radio" th:field="*{warehouse}" value="C仓库" title="C仓库">
            <input type="radio" th:field="*{warehouse}" value="商店" title="商店">

        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">入库日期</label>
        <div class="layui-input-block">
            <input type="text" th:field="*{time}" required="required"  lay-verify="required" placeholder="请输入货物入库日期" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">数量</label>
        <div class="layui-input-block">
            <input type="text" th:field="*{quantity}" required="required"  lay-verify="required" placeholder="请输入数量" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">单价</label>
        <div class="layui-input-block">
            <input type="text" th:field="*{sal}" required="required"  lay-verify="required" placeholder="请输入价格" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">负责人</label>
        <div class="layui-input-block">
            <input type="text" th:field="*{people}" required="required"  lay-verify="required" placeholder="请输入负责人名称" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <textarea th:field="*{record}" placeholder="" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button id="btn-submit" class="layui-btn" lay-submit lay-filter="btn-submit-filter">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script th:src="@{/layui/layui.js}" charset="utf-8"></script>
<script th:inline="javascript">
    var ctxPath = [[@{/}]];

        layui.use(['laydate','table','form'], function(){
            var laydate = layui.laydate;
            var table = layui.table;
            var form = layui.form;
            var $ = layui.$;
            laydate.render({
                elem: '[name="time"]' //指定元素
            });


            //表单提交

            form.on('submit(btn-submit-filter)', function(data){
                // 将登录按钮置灰
                $("#btn-submit").attr("disabled","disabled").addClass("layui-btn-disabled");

                // 异步请求提交数据

                var url = ctxPath + "goods";
                data.field._method = "PUT";
                $.post(url,data.field,function (response){

                    if (response.code == 0){

                        //成功提示
                        layer.msg(response.message, {
                            icon: 1,
                            time: 1000 //1秒关闭（如果不配置，默认是3秒）
                        }, function(){
                            // 刷新表格
                            parent.location.reload(); // 父页面刷新

                            // 关闭窗口
                            //当你在iframe页面关闭自身时
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭

                        });

                        //关闭窗口

                        //刷新表格
                    }else{
                        $("#btn-submit").removeAttr("disabled","disabled").removeClass("layui-btn-disabled");

                        //失败

                        layer.alert(response.message, {
                            icon: 2,
                            anim: 6,
                            title: "编辑失败"

                        });
                        // 将登录按钮取消置灰,恢复可用


                    }






                });



                // 提交成功后则关闭窗口，并且刷新数据表格
                //失败则提示错误信息，窗口不关闭

                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            });




        });
</script>



</body>
</html>